package com.booksmanager.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.booksmanager.annotation.Log;
import com.booksmanager.pojo.BoorowBooks;
import com.booksmanager.pojo.User;
import com.booksmanager.service.BoorowBooksService;
import com.booksmanager.utils.R;
import com.booksmanager.utils.RequestSession;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 借书表 前端控制器
 * </p>
 *
 * @author Yan
 * @since 2020-05-24
 */
@Api(value = "/boorowbooks", tags = "借书接口模块")
@RestController
@RequestMapping("/boorowbooks")
public class BoorowBooksController {

    @Autowired
    private BoorowBooksService boorowBooksService;


    /**
     * 分页查询图书列表
     *
     * @param page
     * @param boorowBooks
     * @return
     */
    @ApiOperation(value = "分页查询图书列表")
    @GetMapping("/page")
    public R page(Page page, BoorowBooks boorowBooks) {
        return new R(boorowBooksService.queryBoorowBooks(page, boorowBooks));
    }

    /**
     * 借书
     *
     * @param boorowBooks
     * @return
     */
    @ApiOperation(value = "借书")
    @Log("借书")
    @PostMapping("/save")
    public R save(@RequestBody BoorowBooks boorowBooks) {
        RequestSession<User> requestSession = new RequestSession<>();
        boorowBooks.setCreateId(requestSession.getUser().getId());
        boorowBooks.setCreateName(requestSession.getUser().getHolder());
        return new R(boorowBooksService.save(boorowBooks));
    }


}

